//
//  MainAccountSelectCell.swift
//  d11
//
//  Created by peale on 2018/9/17.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class MainAccountSelectCell: UITableViewCell {
    var bgImgView : UIImageView?
    var iconImgView : UIImageView?
    var titleLabel : UILabel?
    var subTileLabel : UILabel?
    var arrowImgView : UIImageView?
    var lineView : UIView?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.bgImgView = UIImageView.init()
        self.bgImgView?.image = imageNamed("icon_my_cell_center")
        self.bgImgView?.isUserInteractionEnabled = true
        self.contentView.addSubview(bgImgView!);
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-10)
            make.height.equalTo(51)
            make.centerX.equalTo(self.contentView)
        };
        
        self.iconImgView = UIImageView.init()
        self.iconImgView?.image = imageNamed("icon_mainAccount_in")
        self.bgImgView?.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(25)
            make.width.equalTo(19)
            make.height.equalTo(13.5)
            make.centerY.equalTo(self.bgImgView!)
        }
        
        
        self.titleLabel = UILabel.init()
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.bgImgView?.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.iconImgView?.snp.right)!).offset(15)
            make.width.equalTo(40)
            make.centerY.equalToSuperview()
            make.height.equalTo(25)
        }
        
        
        self.arrowImgView = UIImageView.init()
        self.arrowImgView?.image = imageNamed("icon_common_cell_arrow")
        self.bgImgView?.addSubview(self.arrowImgView!)
        
        self.arrowImgView?.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-15)
            make.width.equalTo(6)
            make.centerY.equalTo(self.bgImgView!)
            make.height.equalTo(12)
        }
        
        self.subTileLabel = UILabel.init()
        self.subTileLabel?.textColor =  HexRGBAlpha(0x8E8F90, 1)
        self.subTileLabel?.font = UIFont.systemFont(ofSize: 15)
        self.subTileLabel?.textAlignment = NSTextAlignment.right
        self.bgImgView?.addSubview(self.subTileLabel!)
        
        self.subTileLabel?.snp.makeConstraints{(make) in
            make.right.equalTo((self.arrowImgView?.snp.left)!).offset(-12)
            make.width.equalTo(kScreenWidth-21-12-55-45-10)
            make.centerY.equalTo(self.bgImgView!)
            make.height.equalTo(25)
        }
        
        self.lineView = UIView.init()
        self.lineView?.backgroundColor = HexRGBAlpha(0xF7F8F8, 1)
        self.bgImgView?.addSubview(self.lineView!)
        
        self.lineView?.snp.makeConstraints{(make) in
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-35)
            make.height.equalTo(0.7)
            make.bottom.equalToSuperview()
        }
    }
    
   
    func setData(iconName:String,title:String,dict:[String:Any]?) -> Void {
        self.iconImgView?.image = imageNamed(iconName)
        self.titleLabel?.text = title
        if dict == nil {
            self.subTileLabel?.text = "请选择"
        }else{
            self.subTileLabel?.text = dict?["name"] as? String
        }
    }

}
